public class HomeWork4 {
    public static void main(String[] args) {
        int count = 1;

        for (int i = 2; i<1000; i ++) {
            if (isPrime(i) && isHuiwen(i)) {
                System.out.print(i+" ");
                if (count % 10 == 0) {
                    System.out.println();
                }
                if (count == 100) {
                    break;
                }
                count++;
            }
        }

    }

    private static boolean isPrime(int num) {
        for (int i = 2; i <= num / 2; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

    private static boolean isHuiwen(int num){
        String str = "" + num;
        int n = str.length();
        for(int i = 0, j = n - 1;  i < n / 2; i ++, j --)
            if(str.charAt(i) != str.charAt(j)) {
                return false;
            }
        return true;
    }
}
